#pragma once

#include "msgdef.h"
#include "singleton.h"
#include "sqlite3pp_helper.h"
#include <map>

namespace zx {
class EventRecords {
    SINGLETON_DECL(EventRecords)

public:
    EventRecords(/* args */) {}
    ~EventRecords() { close(); }
    void open(std::string path);
    void close(void);

    void events_add(events_t& item);
    int events_count(int min_type, int max_type, std::string plate, int level, uint64_t start_time, uint64_t end_time);
    event_query_t events_get(int min_type, int max_type, std::string plate0, int level0, uint64_t start_time,
                             uint64_t end_time, int page_num, int page_size);

    void events_set_invalid(std::string id);
    void events_delete(std::string id);

    std::map<int, int>
    statistics_count(int min_type, int max_type, std::string plate, uint64_t start_time, uint64_t end_time);
    std::string statistics_get(int min_type, int max_type, std::string plate, uint64_t start_time, uint64_t end_time);

    void records_add(records_t& item);
    int records_count(std::string plate0, std::string position0, uint64_t start_time, uint64_t end_time);
    records_query_t records_get(std::string plate0, std::string position0, uint64_t start_time, uint64_t end_time,
                                int page_num, int page_size);

    void cars_add(cars_t& item);
    int cars_count(cars_t& item);
    cars_query_t cars_get(cars_t& item, int page_num, int page_size);

private:
    Sqlite3pp m_conn;
};
}  // namespace zx

#define EventRecordsHandler zx::EventRecords::instance()